package rbe.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Array2StrConverter {

	public Integer[] stringtoArray( String s)  {
		// System.out.print(Arrays.toString(s.split("(\\s)+")));
		List<Integer> elements=new ArrayList<Integer>();  
		for (String s_:s.split("(\\s)+")){
			// System.out.println(s_);
			elements.add(Integer.valueOf(s_.trim()));
		}
		return elements.toArray(new Integer[0]);
	}
	
	public String arrayToString(String[] a, String separator) {
	    if (a == null || separator == null) {
	        return null;
	    }
	    StringBuilder result = new StringBuilder();
	    if (a.length > 0) {
	        result.append(a[0]);
	        for (int i=1; i < a.length; i++) {
	            result.append(separator);
	            result.append(a[i]);
	        }
	    }
	    return result.toString();
	  }
	  
	  public static void main(String args[]) throws Exception {
	    String str =new Array2StrConverter().arrayToString(new String[] { "1" , "56", "12" } ,  ",");
	    System.out.print(Arrays.toString(new Array2StrConverter().stringtoArray("12    56 999"  )));
		System.out.print(Arrays.toString("12    56 999".split("(\\s)+")));
	  }
	  


}
